*Replication Do-File #3: Figure 2, Table 1, Table 2
*Sigman, Rachel, "Which Jobs for Which Boys? Party Finance and the Politics of State Job Distribution in Africa"
*Comparative Political Studies
*Conditional Acceptance: April 9, 2021

***THIS DO-FILE INCLUDES CODE FOR ALL MINISTER-RELATED ANALYSIS FOUND IN SECTION 5

log using "WJWB_MinisterAnalysis_Log.smcl", replace

*******************************************************
****FIGURE 2: COMPARE MINISTER POLITICIZATION SCORES***
*******************************************************

use "Sigman_MinisterDataFull_replication.dta", clear

***Summary Statistics by Country***
bysort country: sum politicization

***Line graph comparing Politicization scores over time***
grstyle init
grstyle set ci
grstyle set mesh, horizontal compact minor 

preserve 
collapse politicization, by(country appt_year)
graph twoway (lpolyci politicization appt_year if country == "Benin") (lpolyci politicization appt_year if country == "Ghana"), legend(off) ylabel(-1(.5)1) xtitle("") ytitle("Average Minister Politicization Score")
restore
*NOTE: Graph editor used to format graph

***Number of MPs appointed:
tab mpattimeofappt country if country == "Ghana", col
*63.77 in Ghana

tab mpattimeofappt presterm if country == "Ghana", col
*74.51% in Kufuor's second term (presterm=10)

*************************************************************
****TABLE 1: MINISTER PLACEMENT & EXTRACTION OPPORTUNITIES***
*************************************************************

use "WJWB_Table2_replication", replace

est clear

***Descriptive Statistics (Table D.1 in Supplementary Material)
tabstat loy_pol log_price log_contracts log_staff appt electionyear if year>2011 & year<2017, stat(mean sd min max N) col(stat)


***Table 2: Are ministries with more contracting opportunities more likely to receive a politically loyal minister?***
xtreg loy_pol log_price if mincode != 61 & mincode != 52, robust cluster(mincode)
est sto mod1
xtreg loy_pol log_contracts if mincode != 61 & mincode != 52, robust cluster(mincode)
est sto mod2

xtreg loy_pol log_price percent_mdatot log_staff appt electionyear if mincode != 61 & mincode != 52, robust cluster(mincode)
est sto mod3
xtreg loy_pol log_contracts percent_mdatot log_staff appt electionyear if mincode != 61 & mincode != 52, robust cluster(mincode)
est sto mod4
xtreg loy_pol log_price percent_mdatot log_staff appt electionyear if mincode != 61 & mincode != 52, fe robust cluster(mincode)
est sto mod5
xtreg loy_pol log_contracts percent_mdatot log_staff appt electionyear if mincode != 61 & mincode != 52, fe robust cluster(mincode)
est sto mod6

esttab mod1 mod2 mod3 mod4 mod5 mod6, r2 b(3) ///
label star(* 0.10 ** 0.05 *** 0.01)

***Robustness check with web-based data only (Table D.2 in Supplementary Material)***
xtreg loy_pol log_price if mincode != 61 & mincode != 52 & source == "web", robust cluster(mincode)
est sto mod7
xtreg loy_pol log_contracts if mincode != 61 & mincode != 52 & source == "web", robust cluster(mincode)
est sto mod8

xtreg loy_pol log_price percent_mdatot log_staff appt electionyear if mincode != 61 & mincode != 52 & source == "web", robust cluster(mincode)
est sto mod9
xtreg loy_pol log_contracts percent_mdatot log_staff appt electionyear if mincode != 61 & mincode != 52 & source == "web", robust cluster(mincode)
est sto mod10
xtreg loy_pol log_price percent_mdatot log_staff appt electionyear if mincode != 61 & mincode != 52 & source == "web", fe robust cluster(mincode)
est sto mod11
xtreg loy_pol log_contracts percent_mdatot log_staff appt electionyear if mincode != 61 & mincode != 52 & source == "web", fe robust cluster(mincode)
est sto mod12

esttab mod7 mod8 mod9 mod10 mod11 mod12, r2 b(3) ///
label star(* 0.10 ** 0.05 *** 0.01)

***********************************************
****TABLE 2: MINISTER ROTATION AND DISMISSAL***
***********************************************

use "Sigman_MinisterDataFull_replication.dta", clear


***Drop if dates missing***
drop if appt_year == . | end_year == .

***Generate variable for how tenure ended***
so min_id appt_date
gen end_type = .
order end_type, after(end_year)
replace end_type = 1 if end_year == appt_year[_n+1] & min_id == min_id[_n+1]
replace end_type = 2 if end_type != 1 & appt_year != . & end_year != .
replace end_type = 3 if end_date == date("09apr1996", "DMY") & country_id ==1
replace end_type = 3 if end_date == date("07may2001", "DMY") & country_id ==1
replace end_type = 3 if end_date == date("08apr2006", "DMY") & country_id ==1
replace end_type = 3 if end_date == date("29may2011", "DMY") & country_id ==1
replace end_type = 3 if end_date == date("06apr2016", "DMY") & country_id ==1
replace end_type = 3 if end_date == date("07jan1997", "DMY") & country_id ==2
replace end_type = 3 if end_date == date("07jan2001", "DMY") & country_id ==2
replace end_type = 3 if end_date == date("07jan2005", "DMY") & country_id ==2
replace end_type = 3 if end_date == date("07jan2009", "DMY") & country_id ==2
replace end_type = 3 if end_date == date("07jan2013", "DMY") & country_id ==2
replace end_type = 3 if end_date == date("07jan2017", "DMY") & country_id ==2

label var end_type "How did the minister's tenure end?"
lab define end_type 1 "rotation" 2 "intra-term exit" 3 "election/newgov"

gen intraterm_exit = 0 if end_type !=.
replace intraterm_exit = 1 if end_type == 2

***Table 2, Row 1***
tab intraterm_exit country_id, col
prtest intraterm_exit, by(country)

***Table 2, Row 2***

*Calculate annual entry, rotation, exit
preserve
rename appt_year year
collapse (count)appt_id, by(country_id year)
save "min_entry.dta", replace
restore

preserve
rename end_year year
collapse (count)appt_id, by(country_id year)
save "min_exit.dta", replace
restore

*Merge entry and exit
use "min_entry.dta", clear
rename appt_id enter

merge m:m country_id year using "min_exit.dta", keepusing (appt_id)
rename appt_id exit
drop _merge

order country_id, before(year)

drop if year>2016

*Create observations for years in which there are no changes
so country_id year
insobs 1, before(2)
replace year = 1992 in 2
replace country_id = 1 in 2

insobs 1, before(7)
replace year = 1997 in 7
replace country_id = 1 in 7

insobs 1, before(10)
replace year = 2000 in 10
replace country_id = 1 in 10

insobs 1, before(14)
replace year = 2004 in 14
replace country_id = 1 in 14

insobs 1, before(28)
replace country_id = 2 in 28
replace year = 1994 in 28

insobs 1, before(38)
replace country_id = 2 in 38
replace year = 2004 in 38

replace enter = 0 if enter == .
replace exit = 0 if exit == .

gen country = "Benin" if country_id == 1
replace country = "Ghana" if country_id == 2
order country, after(country_id)

*Create variable for total number of ministers
xtset country_id year

gen total_min = .
replace total_min = enter if year == 1991 & country_id == 1
replace total_min = enter if year == 2016 & country_id == 1
replace total_min = l.total_min + enter - exit if country_id == 1 & year>1991 & year<2016

replace total_min = enter if year == 1993 & country_id == 2
replace total_min = l.total_min + enter - exit if country_id == 2 & year>1993

*Create volatility variable
gen volatility = (enter+exit)/total_min

*Create inauguration year dummy variable
gen inaug_year = 0
replace inaug_year = 1 if year == 1991 & country_id == 1
replace inaug_year = 1 if year == 1996 & country_id == 1
replace inaug_year = 1 if year == 2001 & country_id == 1
replace inaug_year = 1 if year == 2006 & country_id == 1
replace inaug_year = 1 if year == 2011 & country_id == 1
replace inaug_year = 1 if year == 2016 & country_id == 1
replace inaug_year = 1 if year == 1993 & country_id == 2
replace inaug_year = 1 if year == 1997 & country_id == 2
replace inaug_year = 1 if year == 2001 & country_id == 2
replace inaug_year = 1 if year == 2005 & country_id == 2
replace inaug_year = 1 if year == 2009 & country_id == 2
replace inaug_year = 1 if year == 2013 & country_id == 2

*Compare intra-term volatility across countries
ttest volatility if inaug_year == 0, by(country_id)

***Table 2, Row 3***
gen percent_turnover = exit/total_min
bysort country: sum percent_turnover if inaug_year == 0
ttest percent_turnover if inaug_year == 0, by(country)

***Table 2, Row 4***

use "Sigman_MinisterDataFull_replication.dta", clear

*Create variable for days served
gen days = end_date - appt_date
ttest days, by(country)

***Table 2, Row 5***

bysort country: sum politicization, de
*Benin median = -0.2315
*Ghana median = 0.4052

gen politicization_high = 0 
replace politicization_high = 1 if politicization > -0.2315 & country_id == 1
replace politicization_high = 1 if politicization > 0.4052 & country_id == 2

ttest days if politicization_high == 1, by(country)

***Table 2, Row 6***
bysort country: sum appt_id
*Benin 310 observations
*Ghana 276 observations

***Table 2, Row 7***
codebook min_id if country == "Benin" 
*unique values = 250
codebook min_id if country == "Ghana"
*unique values = 166

***Table 2, Row 8***
bysort country: sum appt_year

log close
